<?php
class gyxj_favoritesModel extends spModel
{
    public $pk = "id"; // 主键
    public $table = "gyxj_favorites"; // 对应数据表

    /**
     * 检查是否已收藏
     * @param string $user_id 用户ID
     * @param string $content_type 内容类型(culture/ai)
     * @param int $content_id 内容ID
     * @return bool
     */
    public function isCollected($user_id, $content_type, $content_id)
    {
        $condition = [
            'user_id' => $user_id,
            'content_type' => $content_type,
            'content_id' => $content_id
        ];
        return $this->find($condition) ? true : false;
    }

    /**
     * 获取用户收藏列表
     * @param string $user_id 用户ID
     * @param int $page 页码
     * @param int $pageSize 每页条数
     * @return array
     */
    public function getUserFavorites($user_id, $page = 1, $pageSize = 10)
    {
        $start = ($page - 1) * $pageSize;
        return $this->findSql("SELECT * FROM {$this->table} WHERE user_id = '{$user_id}' ORDER BY collect_time DESC LIMIT {$start}, {$pageSize}");
    }
}
?>